/*
 * casinfo.h
 *
 *  Created on: 2016年6月13日
 *      Author: guyadong
 */

#ifndef FACEDETECT_CASINFO_H_
#define FACEDETECT_CASINFO_H_
#include <vector>
#include <cmath>
#include <iostream>
#include <stdexcept>
#include "detect_cl.h"
#include "cl_utilits.h"
#include "cl-files/adaboost_face.h"
#include "measure.h"
namespace gdface{
// 定义在 cl-files/adaboost_face.h
//opencl源码中不支持中文，所以在这里对结构进行中文注释
/*
typedef struct{
	cl_int x;//特征矩形所在位置
	cl_int y;
	cl_int Width;

	cl_int Height;//特征矩阵大小
	cl_int Up_Down;
	cl_uchar RectangleNum;//矩形数目
	cl_int  Valve;//阀值
	cl_float DValve;
	cl_int Sign;//阀值的方向
	cl_int CorrectNum;
	cl_int NonfaceCorrectNum;
	cl_int unitWidth;
	cl_int unitHeight;
}feather_cl;
*/


void magnify_feather(feather_cl &feather_dst,const feather_cl &feather_src,double magnify_ratio);
feather_cl magnify_feather(const feather_cl &feather_src,double magnify_ratio);
void magnify_feathers_level(feather_cl*feathers_dst,const feather_cl*feather_src,size_t size,double magnify_ratio);
std::vector<feather_cl> magnify_feathers_level(const feather_cl*feather_src,cl_int size,double magnify_ratio);
std::vector<feather_cl> magnify_feathers_from0(const feather_cl*fv0_ptr,size_t fv0_size,size_t level_num,double magnify_ratio);

std::vector<feather_short_cl> convert_short(const std::vector<feather_cl>&feathers);
struct casinfo_cl:casinfo_base {
	/*
	cl_int CasNum;//总层数
	cl_int FeaNumPerLayer[MAX_LAYER_NUM];//每层特征的数目
	cl_double Weight[MAX_WEIGHT_NUM];//每个特征权值
	cl_double LayerWeight[MAX_LAYER_NUM];//每层权值
	cl_int FeatherNumPerCas;//特征总数目
	*/
	std::vector<feather_cl> Feather;
	size_t level_num = SCALE_SIZE;	// 分类器放大级数
	float magnify_ratio=.0f; // 分类器放大分辨率
	/*
	 * 根据放大级数(level_num)和放大倍率(magnify_ratio)重建分类器
	 */
	casinfo_cl& build_feathers(const measure&m);
};

casinfo_cl load_casinfo(std::istream& in,size_t scale_num= SCALE_SIZE,float magnify_ratio= DETECT_WIN_SCALE_RATIO);
casinfo_cl load_casinfo_file(const std::string& file,size_t scale_num= SCALE_SIZE,float magnify_ratio= DETECT_WIN_SCALE_RATIO);
casinfo_cl load_casinfo_json(const std::string& json);
#ifdef CASINFO_EMBEDDED
casinfo_cl load_casinfo_from_code();
#endif
casinfo_cl load_casinfo_json_compressed(const void* json_compressed_ptr,size_t length,size_t uncompress_bound=0);
casinfo_cl load_casinfo_json_compressed_base64(const std::string& json_compressed,size_t uncompress_bound=0);
casinfo_cl load_casinfo_json_file(const std::string& file);

std::string casinfo_to_json_str(const casinfo_cl& cas,bool full=false,bool compressed=false,bool base64=false);
void save_casinfo_json(const casinfo_cl&cas,std::ostream &stream, bool fast=false,bool full=false);
void save_casinfo_json_file(const casinfo_cl& cas, const std::string& file,bool full=false);
casinfo_base_float to_casinfo_base_float(const casinfo_base& cas);
}/* namespace gdface */
#endif /* FACEDETECT_CASINFO_H_ */
